package com.mhwx.mhlive.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mhwx.mhlive.R;
import com.mhwx.mhlive.model.UserContent;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by luxiaoman on 2016/12/5.
 */
public class UserAdapter extends UserBaseAdapter<UserContent> {
    private ListItemClickListener listItemClickListener;

    public UserAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case UserContent.HEADER:
                view = LayoutInflater.from(mContext).inflate(R.layout.user_header_item_view, parent, false);
                break;

            case UserContent.ITEM:
                view = LayoutInflater.from(mContext).inflate(R.layout.user_list_item_user, parent, false);
                break;
        }
        return new ConfigViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        UserContent item = getList().get(position);
        final String title = item.getItemName();
        ConfigViewHolder configViewHolder = (ConfigViewHolder) holder;
        switch (item.getItemType()) {
            case UserContent.HEADER:

                break;
            case UserContent.ITEM:
                configViewHolder.img.setImageResource(item.getItemIcon());
                configViewHolder.title.setText(item.getItemName());
                break;
        }
//        configViewHolder.itemLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                listItemClickListener.onItemClick(title);
//            }
//        });
    }


    @Override
    public int getItemViewType(int position) {
        return getList().get(position).getItemType();
    }

    public void setOnItemClickListener(ListItemClickListener l) {
        this.listItemClickListener = l;
    }

    public interface ListItemClickListener {
        void onItemClick(String title);
    }

    public class ConfigViewHolder extends RecyclerView.ViewHolder {


        @Nullable
        @BindView(R.id.img)
        ImageView img;

        @Nullable
        @BindView(R.id.title)
        TextView title;



        public ConfigViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
